home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
fbuilder
/
delphi
/
fbcalc.pa1
< prev
next >
Wrap
Text File
|
1996-09-15
|
26KB
|
720 lines
{
// FORMULABUILDER 1.0
// YGB Software, Inc.
// An Advanced Expression Evaluation Engine
// Copyright 1995 Clayton Collie, All Rights Reserved
//
// Pascal Import unit for Formula Builder DLL
// Explicit Linking Version
//
//
// NOTE! Included for informational purposes only ! DO NOT modify and
// recompile, as this will cause a unit version mismatch error in the
// component units.
}
unit fbcalc;
INTERFACE
Uses Wintypes;
CONST
FBuilderLib = 'FBCALC.DLL';
TYPE
Float = Double;
TFBString = PString;
{$IFDEF VER80}
TFBDate = TDateTime;
{$ELSE}
TFBDate = Double;
{$ENDIF}
HEXPR = Longint; { expression handle type }
CONST
MAXFUNCPARAMS = 16; { Functions can have up to MAXFUNCPARAMS parameters }
{::::::::::::::::::: Variable/Datatype constants:::::::::::::::::::::: }
{ vtInteger .. vtClass taken from \delphi\doc\system.int}
vtINTEGER = 0;
vtBOOLEAN = 1;
vtCHAR = 2;
vtFLOAT = 3;
vtSTRING = 4;
vtPOINTER = 5;
vtPCHAR = 6; { unused }
vtDATE = 9;
vtBOOL = 10;
vtANY = 11;
vtNONE = 13;
vtTypeClash = 14;
vtTypeMismatch = vtTypeClash;
CONST
BOOLTRUE = WORD(1);
BOOLFALSE = WORD(0);
type
datatypes = vtInteger .. vtNone;
datatypeset = set of Datatypes;
CONST
EXPR_SUCCESS = 1;
EXPR_MISSING_PAREN = 2;
EXPR_BAD_EXPRESSION = 3;
EXPR_BAD_ASSIGNMENT = 4;
EXPR_UNKNOWN_IDENT = 5;
EXPR_LINE_TOO_LONG = 6;
EXPR_INVALID_TOKEN = 7;
EXPR_INVALID_CHAR = 8;
EXPR_MISSING_PARAM = 9;
EXPR_TYPE_MISMATCH = 10;
EXPR_INVALID_NUMBER = 11;
EXPR_MISSING_VARIABLE = 12;
EXPR_INVALID_VARIABLE = EXPR_MISSING_VARIABLE; {CC}
EXPR_INVALID_FUNCTION = 13;
EXPR_ZERO_DIVISION = 14;
EXPR_STACK_OVERFLOW = 15;
EXPR_UNEXPECTED_EOS = 16;
EXPR_INVALID_DATE = 17;
EXPR_IDENTIFIER_EXPECTED = 18;
EXPR_RANGE_ERROR = 19;
EXPR_DOMAIN_ERROR = 20;
EXPR_MATH_ERROR = 21;
EXPR_FP_OVERFLOW = 22;
EXPR_FP_UNDERFLOW = 23;
EXPR_INT_OVERFLOW = 24;
EXPR_INVALID_OP = 25;
EXPR_VARIABLE_EXPECTED = 26;
EXPR_MISSING_OPERATOR = 27;
EXPR_MISSING_OPERAND = 28;
EXPR_CONSTANT_EXPECTED = 29;
EXPR_DUPLICATE_IDENT = 30;
EXPR_SYNTAX_ERROR = 31;
EXPR_CONVERT_ERROR = 32;
EXPR_INVALID_TYPE = 33;
EXPR_INVALID_HANDLE = 50;
EXPR_INVALID_CALLBACK = 51;
EXPR_FORMULA_TOO_COMPLEX = 54;
Const IDI_MAIN = 1;
IDS_TRUE = 2;
IDS_FALSE = 3;
TYPE
{ General value structure }
PValueRec = ^TValueRec;
TValueRec = record
flags : byte;
case vtype : datatypes of
vtInteger : (vInteger : Longint);
vtString : (vpString : TFBString);
vtBoolean : (vBoolean : Boolean);
vtChar : (vChar : Char);
vtFloat : (vFloat : Float);
vtPChar : (vpChar : PChar);
vtPointer : (vPointer : Pointer);
vtDate : (vDate : TFBDate);
vtBOOL : (vBOOL : BOOL);
end;
{
// Callback definitions for variable & field implementation
}
TYPE
TCBKGetVariable =
function(varname : pchar;
var value : TValueRec;
vardata : longint;
CBKData : longint):integer;
TCBKSetVariable =
function(varname : pchar;
value : TValueRec;
vardata : longint;
CBKData : longint):integer;
TCBKFindvariable =
function(varname : pchar;
var vtype : byte;
var VarData : longint;
CBKData : longint):integer;
{ function enumeration Callback }
TCBKEnumFunctions =
function(vname : pchar;vtype : byte;parms : pchar;bMinPrms : byte;lEnumData : longint):integer;
{******************************************************
* Declarations for external function implementation
******************************************************}
{
// Actual parameter list passed to external function callback
// The parser engine ensures that these match, in number and
// type, the prototype specified when the callback was registered
}
PActParamlist = ^TActParamlist;
TActParamList = array[0..MAXFUNCPARAMS-1] of TValueRec;
{
// Prototypes for external user-defined functions
// Implemented routine MUST use the EXPORT clause
}
TCBKExternalFunc =
procedure(paramcount : byte;
const params : TActParamlist;
var retvalue : TValueRec;
var errcode : integer;
ExprData : longint);
var
{
//
// Functions and Procedures
//
}
{*----------------------------------------------*}
{ Engine initialization and shutdown }
{*----------------------------------------------*}
FBInitExpression : Function(lExprData : longint) : longint;
FBFreeExpression : Function(handle : HEXPR) : integer;
{::::::::::::::::::::: Expression Manipulation ::::::::::::::::::::}
FBSetExpression : Function(handle : HEXPR;expr : pchar):integer;
FBReparseExpression : Function(handle : HEXPR):integer;
FBClearExpression : Function(handle : HEXPR) : integer;
FBGetExpression : Function(handle : HEXPR;lpszBuf : pchar;wBuflen : word):integer;
{::::::::::::::::::::: Expression Evaluation :::::::::::::::::::::::}
{ determine the result type of the expression. Returns one of the }
{ vtXXX constants, vtTYPEMISMATCH for an invalid expression }
FBGetReturnType : Function(handle : HEXPR) : integer;
{
// Evaluate the expression, returning a maximum of maxlen characters
// of the null-terminated string result in the buffer/string pointed to
// by outbuf
}
FBEvaluate : Function(handle : HEXPR;lpszBuf : pchar;wBuflen : word):integer;
{*
* Evaluate the expression, returning the result in a TValueRec structure
* FBFreevalue should be used to dispose of any memory associated with value
* when it is no longer needed
*}
FBEvaluatePrim : Function(handle : HEXPR;var value : TVALUEREC):integer;
{* Dispose of any memory associated with a TValueRec structure *}
FBFreeValue : Procedure(var Value : TValueRec);
FBCopyValue : Function(value : TValueRec):TValueRec;
{*
* Routines to get the expression results in primitive types
*}
FBGetStringResult : Function(handle : HEXPR;value : pchar;maxlen : word):integer;
FBGetFloatResult : Function(handle : HEXPR;var value : double):integer;
FBGetBooleanResult : Function(handle : HEXPR;var value : BOOL):integer;
FBGetIntegerResult : Function(handle : HEXPR;var value : longint):integer;
FBGetDateResult : Function(handle : HEXPR;var value : TFBDate):integer;
{*======================================================================*}
{ Perform a single operation expression evaluation. This is not the most }
{ efficient method of evaluation when the expression remains the same }
{*======================================================================*}
FBEvalExpression : Function(expr : pchar;var retType : datatypes;
buf : pchar;maxlen : word):integer;
{::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::}
{ Internal Variable handling routines. NOTE ! If the variable callbacks are }
{ implemented, the evaluation engine will not see the var